package com.smart.stock.module.maindata.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.smart.stock.common.util.Result;
import com.smart.stock.common.util.db.DBUtil;
import com.smart.stock.common.util.h2.H2Util;
import com.smart.stock.common.util.spring.EntityUtil;
import com.smart.stock.module.maindata.entity.Stock;
import com.smart.stock.module.maindata.entity.StockCollect;
import com.smart.stock.module.maindata.entity.StockPriceDaily;
import com.smart.stock.module.maindata.services.*;
import com.smart.stock.module.spider.jobSpiderApi.XueQiuApi;
import com.smart.stock.module.spider.util.TradingDateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


@Api(tags = "股票收藏")
@Slf4j
@Controller
@RequestMapping("/stockCollect")
public class StockCollectController {

    @Autowired
    private StockService service;

    @Autowired
    private StockCollectService stockCollectService;

    @Autowired
    private StockCodeInfoService stockCodeInfoService;
    @Autowired
    private StockDailyPriceServices stockDailyPriceServices;
    @Autowired
    private TradingDateUtil tradingDateUtil;
    @Autowired
    private XueQiuApi xueQiuApi;
    @Autowired
    private MongoTemplate template;
    @Autowired
    private StockDailyIndexesService stockDailyIndexesService;

    @GetMapping("/index")
    public String index(Model model) {
        return "/stock/collect/collect";
    }


    @PostMapping("/addcollect")
    @ResponseBody
    public String addcollect(String codes,String names) {
//        List<Stock> stocks = service.getStockByCodes(codes.split(","));
//        System.out.println(stocks);
        stockCollectService.addCollect(codes.split(","));
        return "ok";
    }

    @PostMapping("/delcollect")
    @ResponseBody
    public String delcollect(String codes) {
        stockCollectService.delcollect(codes.split(","));
        return "ok";
    }

    @PostMapping("/list")
    @ResponseBody
    public String list() {
        List<StockCollect> list = stockCollectService.list();
        return JSONArray.toJSONString(list);
    }



}
